var fetch = require('@system.fetch');

var API_ROOT = 'http://web.juhe.cn:8080/';
//var API_ROOT ="http://tapi.ym1998.com/";
var headers = {
	'Content-Type': 'application/x-www-form-urlencoded'
};
var key = 'fb4e063288db49c85e2ba433dab26be8';

function getTimestamp() {
	let nowDate = new Date();
	let hours = nowDate.getHours();
	let minutes = nowDate.getMinutes();
	let seconds = nowDate.getSeconds();
	if (hours < 10) {
		hours = '0' + String(hours);
	}
	if (minutes < 10) {
		minutes = '0' + String(minutes);
	}
	if (seconds < 10) {
		seconds = '0' + String(seconds);
	}
	return String(hours) + String(minutes) + String(seconds);
}

function realFetch(url, data = null, method = 'get') {
	if (data == null) {
		data = {};
	}
	return new Promise((resolve, reject) => {
		fetch.fetch({
			url: API_ROOT + url,
			data: data,
			header: headers,
			method: method,
			success: function(data) {
				resolve(data);
			},
			fail: function(data, code) {
				reject(data, code);
			}
		});
	});
}

function post(url, data = null) {
	return realFetch(url, data, 'post');
}

function get(url, data = null) {
	return realFetch(url, data, 'get');
}

export  function getConstell(consName,type='today') {
		return post('constellation/getAll',{consName:consName,type:type,key:key}).then((response) => {
			console.log(JSON.parse(response.data));
            return Promise.resolve(JSON.parse(response.data));
        }).catch((err) => {
            return Promise.reject(err);
        })
}

/*	setCrbt(order_from, mobile, resource_id, device_info) {
		return post('client/biz/set_crbt', {
			order_from: order_from,
			mobile: mobile,
			resource_type: 1,
			resource_id: resource_id,
			device_info: device_info
		});
	},
	/!**
	 * 保存意见反馈
	 * @param {String} content 
	 * @param {String} contact 
	 * @param {String} device_info 
	 *!/
	saveAdvice(content, contact, device_info) {
		return post('client/user/submit_adivce', {
			type: 1,
			content: content,
			contact: contact,
			device_info: device_info
		});
	}
};*/
